package com.yfqy.app.enums;

import lombok.Getter;

/**
 * 系统错误码枚举
 * 编码规则：
 * - 0: 成功
 * - 1xxx: 系统通用错误
 * - 2xxx: 用户认证授权相关
 * - 3xxx: 商品管理相关
 * - 4xxx: 订单管理相关
 * - 5xxx: 促销活动相关
 * - 6xxx: 积分系统相关
 * - 7xxx: 分销系统相关
 * - 8xxx: 系统配置相关
 * - 9xxx: 第三方服务相关
 */
@Getter
public enum ErrorCode {
    // ==================== 成功 ====================
    SUCCESS(0, "操作成功"),

    // ==================== 系统通用错误 (1xxx) ====================
    BAD_REQUEST(1001, "请求参数错误"),
    METHOD_NOT_ALLOWED(1002, "请求方法不允许"),
    NOT_FOUND(1003, "资源不存在"),
    SYSTEM_ERROR(1004, "系统繁忙，请稍后重试"),
    DB_OPERATION_ERROR(1005, "数据库操作失败"),
    REQUEST_TOO_FREQUENT(1006, "请求过于频繁，请稍后重试"),

    // ==================== 用户认证授权相关 (2xxx) ====================
    NEED_LOGIN(2001, "需要登录后操作"),
    SIGN_ERROR(2002, "签名错误"),
    NO_OPERATOR_AUTH(2003, "无权限操作"),
    USER_NOT_LOGIN(2004, "用户未登录"),
    USER_NOT_EXIST(2005, "用户不存在"),
    USER_IS_INVALID(2006, "无效的用户"),
    USER_STATUS_ERROR(2007, "用户状态异常"),
    USER_LOCKED(2008, "用户已被锁定，请联系管理员"),
    USER_DELETED(2009, "用户已被删除"),
    INVALID_CREDENTIALS(2010, "用户名或密码不正确"),
    LOGIN_ERROR(2011, "用户名或密码错误"),
    USERNAME_NOT_NULL(2012, "用户名不能为空"),
    USERNAME_EXIST(2013, "用户名已存在，不可重复添加"),
    PHONE_NUMBER_EXIST(2014, "手机号已存在，不可重复添加"),
    EMAIL_EXIST(2015, "邮箱已存在，不可重复添加"),
    ALREADY_IS_LEADER(2016, "您已经是分销商，无需重复申请"),
    LEADER_IS_REFUSED(2017, "近期有被驳回的申请，请7天后再提交"),
    LEADER_APPLY_IS_EXITS(2018, "您已有待审核的申请，请勿重复提交"),

    // ==================== 商品管理相关 (3xxx) ====================
    // 商品基础信息
    PRODUCT_NOT_EXIST_ERROR(3000, "商品信息不存在"),
    PRODUCT_NOT_EXIST(3001, "商品不存在或已下架"),
    PRODUCT_STOCK_INSUFFICIENT(3002, "库存不足"),
    PRODUCT_PRICE_ERROR(3003, "商品价格校验异常"),
    STOCK_NOT_ENOUGH(3004, "库存不足"),
    STOCK_DEDUCT_FAILED(3005, "库存扣减失败"),
    STOCK_LOCK_FAILED(3006, "预扣减库存失败"),
    STOCK_ROLLBACK_FAILED(3007, "库存回滚失败"),

    // 商品规格
    SKU_NOT_EXIST(3010, "商品规格不存在"),
    SKU_SPU_MISMATCH(3011, "商品规格不匹配"),

    // 商品类目
    CATEGORY_IS_INVALID(3020, "无效的商品类目"),
    CATEGORY_IS_EXIST(3021, "商品类目已存在，不可重复添加"),
    CATEGORY_LEVEL_NOT_EXIST(3022, "商品类目级别不存在"),
    CATEGORY_LEVEL2_ICON_NOT_NULL(3023, "二级类目图标不能为空"),
    CATEGORY_LEVEL2_NEED_LEVEL1(3024, "创建二级分类需要选择一级分类"),
    CATEGORY_PARENT_NOT_EXIT(3025, "父级分类不存在"),
    CATEGORY_PARENT_LEVEL_INVALID(3026, "父级分类不存在或无效"),

    // 商品属性
    ATTRIBUTE_NOT_EXIT(3030, "属性校验失败"),

    // 品牌管理
    BRAND_IS_EXIT(3040, "品牌已添加，不可重复添加"),
    BRAND_IS_INVALID(3041, "品牌不存在或无效"),

    // ==================== 订单管理相关 (4xxx) ====================
    ORDER_NOT_EXIST(4001, "订单不存在"),
    ORDER_STATUS_CANNOT_CANCEL(4002, "订单当前状态无法取消"),
    ORDER_TYPE_ERROR(4003, "订单类型不正确"),
    ORDER_ADDRESS_ERROR(4004, "订单收货地址无效"),
    ORDER_ITEM_PARAM_ERROR(4005, "订单商品参数错误"),
    ORDER_STATUS_INVALID(4006, "订单状态异常"),

    // 订单状态相关
    ORDER_PAY_TIMEOUT(4010, "订单已超时未支付"),
    ORDER_SHIPPED(4011, "订单已发货"),
    ORDER_COMPLETED(4012, "订单已完成"),
    ORDER_CANCELLED(4013, "订单已取消，不可重复操作"),
    ORDER_REVIEWED(4014, "订单已评价，不可取消"),
    ORDER_OUTBOUND(4015, "订单已出库"),
    ORDER_CANCEL_FAILED(4016, "订单取消失败"),
    ORDER_APPLY_REFUND(4017, "订单已申请售后"),
    ORDER_CANNOT_APPLY_REFUND(4018, "订单当前状态不可申请售后"),
    ORDER_STATUS_CHANGED(4019, "订单状态已变更，请稍后重试"),
    REFUND_ALREADY_EXISTS(4020, "订单同一商品不可重复申请售后"),
    ORDER_ITEMS_NOT_FOUND(4021, "订单商品不存在"),
    REFUND_ITEMS_INVALID(4022, "订单退款商品无效"),
    REFUND_APPLY_ACCEPTED(4023, "订单售后已受理，取消失败"),

    // 订单售后
    REFUND_PROCESS_RESULT_INVALID(4201, "退款处理结果无效"),
    WECHAT_REFUND_FAILED(4202, "微信退款失败"),
    REFUND_AMOUNT_INVALID(4203, "退款金额无效"),
    REFUND_AMOUNT_EXCEED(4204, "退款金额超过可退金额"),
    ORDER_ALL_REFUNDED(4205, "订单已全部退款"),
    REFUND_NOT_EXIST(4230, "售后订单不存在"),
    REFUND_STATUS_CANNOT_CANCEL(4231, "当前售后订单不可取消"),
    REFUND_NOT_BELONG_TO_USER(4232, "此售后订单不属于自己"),
    REFUND_STATUS_CHANGED(4233, "订单售后状态已发生变化"),
    REFUND_PROCESS_ERROR(4234, "售后处理失败"),

    // ==================== 促销活动相关 (5xxx) ====================
    PROMOTION_NOT_FOUND(5001, "促销活动不存在或已结束"),
    PROMOTION_PRODUCT_NOT_FOUND(5002, "促销活动商品不存在或已下架"),
    PROMOTION_RULE_NOT_FOUND(5003, "促销活动规则不存在"),
    INVALID_PROMOTION_CONFIG(5004, "促销活动配置异常"),
    PURCHASE_LIMIT_EXCEEDED(5005, "您购买的促销活动商品已限购"),
    PROMOTION_IN_PROGRESS(5006, "活动正在进行中不可编辑"),

    // ==================== 积分系统相关 (6xxx) ====================
    INTEGRAL_RULE_NOT_CONFIGURED(6001, "积分抵扣规则未配置"),
    INTEGRAL_NOT_ENOUGH(6002, "用户积分不足"),
    INTEGRAL_RETURN_FAILED(6003, "退回用户积分失败"),
    SIGNED_IN(6004, "今日已签到，请勿重复操作"),

    // ==================== 分销系统相关 (7xxx) ====================
    // 分销相关错误码预留
    NOT_DISTRIBUTOR_USER(7001, "不是分销用户"),

    // ==================== 系统配置相关 (8xxx) ====================
    // 角色管理
    ROLE_ALREADY_EXISTS(8001, "角色已存在，不可重复添加"),
    ROLE_NOTEXIST_INVALID(8002, "角色不存在或已删除"),
    ROLE_CANNOT_DELETED(8003, "此角色不可以删除"),

    // 菜单管理
    MENU_URL_ISNULL(8010, "菜单路由不能为空"),
    MENU_CODE_ISNULL(8011, "权限编码不能为空"),
    MENU_NOT_EXIST(8012, "菜单不存在"),
    MENU_CODE_IS_EXIST(8013, "权限编码已存在"),
    MENU_CANNOT_DELETE(8014, "请先删除子菜单"),
    PARENT_MENU_INVALID(8015, "父菜单不存在或无效"),

    // 系统配置
    CONFIG_NOT_EXIST(8020, "系统配置不存在"),
    CONFIG_VALUE_INVALID(8021, "配置值格式错误"),
    CONFIG_UPDATE_FAILED(8022, "配置更新失败"),

    // ==================== 第三方服务相关 (9xxx) ====================
    // 微信相关
    WECHAT_CONFIG_ERROR(9001, "微信小程序配置缺失"),
    JS_CODE_PARAM_ERROR(9002, "JS_CODE不能为空"),
    WECHAT_API_ERROR(9003, "微信api异常"),

    // 收入记录
    REVENUE_IS_INVALID(9010, "收入记录不存在"),

    // 申请提现
    APPLIES_WITHDRAWAL_AMOUNT_ERROR(10001, "提现金额异常"),
    FUND_ACCOUNT_NOT_EXIST(10002, "用户资金账户不存在"),
    FUND_ACCOUNT_UPDATE_FAILED(10003, "用户资金变更失败"),
    WITHDRAWAL_APPLY_FAILED(10004, "保存提现申请记录失败"),

    AREA_NOT_EXIST(20001, "地址不存在"),
    AREA_NOT_AVAILABLE(20002, "地址未开通"),
    ADDRESS_NO_PERMISSION(20003, "地址不存在或无权操作"),
    ADDRESS_DELETED(20004, "地址已删除"),

    BANNER_NOT_EXIT(30001, "海报不存在"),

    CART_ITEM_NOT_EXIST(2001, "购物车项不存在"),
    CART_ITEM_PURCHASED(2002, "购物车项已购买，无法修改"),
    CART_ITEM_INVALID(2003, "购物车项已失效"),
    ;

    ErrorCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    private final Integer code;
    private final String message;

}